home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 1 / Cream of the Crop 1.iso / PROGRAM / AECUR100.ARJ / SCROLL.C < prev    next >
C/C++ Source or Header  |  1990-03-08  |  2KB  |  72 lines

  1. /*------------------------------------------------------------
  2.  * 
  3.  *  _scroll.c
  4.  * 
  5.  *  copyright (c) 1987,88,89,90 J. Alan Eldridge
  6.  * 
  7.  *  low-level scroll function for Curses! 3.X
  8.  * 
  9.  *----------------------------------------------------------*/
  10.  
  11. #include "curses.h"
  12.  
  13. #define ABS(n) ((n) > 0 ? (n) : -(n))
  14.  
  15. int
  16. _scroll(win, start_line, end_line, lines)
  17. WINDOW  *win;
  18. int     start_line;
  19. int     end_line;
  20. int     lines;
  21. {
  22.     VIDCHR  fillch, 
  23.             *dest, 
  24.             *src;
  25.  
  26.     int     r, 
  27.             c, 
  28.             rows, 
  29.             cols;
  30.     
  31.     if (win->flags & _WSCROLL == 0)
  32.         return ERR;
  33.     
  34.     /* mark the area we're hitting */
  35.     
  36.     getyx(win, r, c);
  37.     wmove(win, start_line, 0);
  38.     markwin(win);
  39.     wmove(win, end_line, getmaxc(win));
  40.     markwin(win);
  41.     wmove(win, r, c);
  42.     
  43.     /* set up fill char, rows, cols */
  44.     
  45.     fillch.chr = ' ';
  46.     fillch.att = win->attrib;
  47.     cols = getmaxc(win) + 1;
  48.     rows = end_line - start_line + 1 - ABS(lines);
  49.     
  50.     /*  3 choices here: clear it, scroll up, or scroll down */
  51.     
  52.     if (rows <= ABS(lines)) {
  53.         /* clear entire area */
  54.     for (r = start_line; r <= end_line; r++)
  55.             memsetw(win->buf[r], &fillch, cols);
  56.     } else if (lines > 0) {
  57.         /* scroll up */
  58.         for (r = start_line; rows-- > 0; r++)
  59.             memcpy(win->buf[r], win->buf[r+1], cols * sizeof(VIDCHR));
  60.         while (r <= end_line) 
  61.             memsetw(win->buf[r++], &fillch, cols);
  62.     } else if (lines < 0) {
  63.         /* scroll down */
  64.         for (r = end_line; rows-- > 0; r--)
  65.             memcpy(win->buf[r], win->buf[r-1], cols * sizeof(VIDCHR));
  66.         while (r >= start_line) 
  67.             memsetw(win->buf[r--], &fillch, cols);
  68.     }
  69.  
  70.     return OK;
  71. }
  72.